package com.hippo.core.ui.compose.control

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties
import com.hippo.core.R
import com.hippo.core.ui.components.BottomDialog
import com.hippo.core.ui.components.BottomSheetDialog
import com.hippo.core.ui.components.KayValueLayout
import com.hippo.core.ui.theme.HippoTheme
import com.thingclips.smart.sdk.bean.DeviceBean
import java.util.Date

@Composable
fun DeviceInfoDialog(
    device:DeviceBean,
    onDismissRequest: () -> Unit,
    modifier: Modifier = Modifier
) {

    BottomSheetDialog(
        title = stringResource(R.string.setting_15),
        onDismissRequest = onDismissRequest,
        modifier = modifier,
    ) {
        DeviceContent(device)
    }
}

@Composable
fun DeviceContent(device:DeviceBean,) {

    Column {

        Text(
            text = stringResource(R.string.setting_20),
            style = MaterialTheme.typography.labelLarge,
            textAlign = androidx.compose.ui.text.style.TextAlign.Center,
            modifier = Modifier.fillMaxWidth().padding(16.dp)
        )
        Text(
            text = stringResource(R.string.setting_21,device.name.orEmpty()),
            style = MaterialTheme.typography.labelSmall,
            textAlign = androidx.compose.ui.text.style.TextAlign.Center,
            modifier = Modifier.fillMaxWidth()
        )

        Spacer(modifier = Modifier.height(30.dp))

        Column(
            modifier = Modifier
                .background(
                    color = MaterialTheme.colorScheme.background,
                    shape = MaterialTheme.shapes.medium
                )
                .padding(16.dp)
        ) {

            KayValueLayout(
                key = stringResource(R.string.setting_22),
                value = device.getUuid(),
                rightAlign = true,
            )

            KayValueLayout(
                key = stringResource(R.string.setting_23),
                value = device.mac,
                rightAlign = true,
            )

            KayValueLayout(
                key = stringResource(R.string.setting_24),
                value = Date(device.getI18nTime()).toLocaleString(),
                rightAlign = true,
            )
        }
    }
}


@Preview(showBackground = true)
@Composable
private fun DeviceInfoDialogPreview() {
    HippoTheme {
        DeviceContent(
            device = DeviceBean(

            )
        )
    }
}

